#include "SMPPMessageDeliveryResponseTLVs.hpp"

using namespace smpp::pdu;

MessageDeliveryResponseTLVs::MessageDeliveryResponseTLVs(
const AdditionalStatusInfoText *nAdditionalStatusInfoText,
const DeliveryFailureReason *nDeliveryFailureReason,
const NetworkErrorCode *nNetworkErrorCode):
_AdditionalStatusInfoText(0),
_DeliveryFailureReason(0),
_NetworkErrorCode(0){
	if(_AdditionalStatusInfoText)
		_AdditionalStatusInfoText = 
		new AdditionalStatusInfoText(*nAdditionalStatusInfoText);
	if(_DeliveryFailureReason)
		_DeliveryFailureReason = new DeliveryFailureReason(
		*nDeliveryFailureReason);
	if(_NetworkErrorCode)
		_NetworkErrorCode = new NetworkErrorCode(*nNetworkErrorCode);
}

MessageDeliveryResponseTLVs::MessageDeliveryResponseTLVs(
const MessageDeliveryResponseTLVs &
nMessageDeliveryResponseTLVs):		
_AdditionalStatusInfoText(0),
_DeliveryFailureReason(0),
_NetworkErrorCode(0){
	if(nMessageDeliveryResponseTLVs.getAdditionalStatusInfoText())
		_AdditionalStatusInfoText = 
		new AdditionalStatusInfoText(
		*nMessageDeliveryResponseTLVs.getAdditionalStatusInfoText());
	if(nMessageDeliveryResponseTLVs.getDeliveryFailureReason())
		_DeliveryFailureReason = new DeliveryFailureReason(
		*nMessageDeliveryResponseTLVs.getDeliveryFailureReason());
	if(nMessageDeliveryResponseTLVs.getNetworkErrorCode())
		_NetworkErrorCode = new NetworkErrorCode(
		*nMessageDeliveryResponseTLVs.getNetworkErrorCode());
}

MessageDeliveryResponseTLVs::~MessageDeliveryResponseTLVs(){
	if(_AdditionalStatusInfoText)
		delete _AdditionalStatusInfoText;
	if(_DeliveryFailureReason)
		delete _DeliveryFailureReason;
	if(_NetworkErrorCode)
		delete _NetworkErrorCode;
}

void MessageDeliveryResponseTLVs::setAdditionalStatusInfoText(
	const AdditionalStatusInfoText *nAdditionalStatusInfoText){
	if(_AdditionalStatusInfoText){
		delete _AdditionalStatusInfoText;
		_AdditionalStatusInfoText = 0;
	}
	if(nAdditionalStatusInfoText)
		_AdditionalStatusInfoText = 
		new AdditionalStatusInfoText(*nAdditionalStatusInfoText);
}

const AdditionalStatusInfoText *
	MessageDeliveryResponseTLVs::getAdditionalStatusInfoText() const{
	return _AdditionalStatusInfoText;
}

void MessageDeliveryResponseTLVs::setDeliveryFailureReason(
	const DeliveryFailureReason *nDeliveryFailureReason){
	if(_DeliveryFailureReason){
		delete _DeliveryFailureReason;
		_DeliveryFailureReason = 0;
	}
	if(nDeliveryFailureReason)
		_DeliveryFailureReason = 
		new DeliveryFailureReason(*nDeliveryFailureReason);
}

const DeliveryFailureReason *
	MessageDeliveryResponseTLVs::getDeliveryFailureReason() const{
	return _DeliveryFailureReason;
}

void MessageDeliveryResponseTLVs::setNetworkErrorCode(
	const NetworkErrorCode *nNetworkErrorCode){
	if(_NetworkErrorCode){
		delete _NetworkErrorCode;
		_NetworkErrorCode = 0;
	}
	if(nNetworkErrorCode)
		_NetworkErrorCode = new NetworkErrorCode(*nNetworkErrorCode);
}

const NetworkErrorCode *
	MessageDeliveryResponseTLVs::getNetworkErrorCode() const{
	return _NetworkErrorCode;
}	

const quint16 MessageDeliveryResponseTLVs::getLength() const{
	quint16 length(0);
	if(_AdditionalStatusInfoText)
		length += 4 + _AdditionalStatusInfoText->getLength();
	if(_DeliveryFailureReason)
		length += 4 + _DeliveryFailureReason->getLength();
	if(_NetworkErrorCode)
		length += 4 + _NetworkErrorCode->getLength();
	return length;
}
